const mysql = require('mysql2/promise')
const config = require('./db-config')

const connection = async () => {
    const pool = await mysql.createPool(config.mysql_connection_options);
    exports.pool = pool;
}

let conn1 = connection()
exports.conn1 = conn1;

////////////服务器版本//////////////////////
/*const mysql = require('mysql2/promise')
const {Connector} = require('@google-cloud/cloud-sql-connector')

const connection = async () => {
    const connector = new Connector();
    const clientOpts = await connector.getOptions({
        instanceConnectionName: 'cameraproject-420608:asia-northeast1:camera-sql-instance',
        ipType: 'PRIVATE',
    });
    //const pool = await mysql.createPool(config.mysql_connection_options);
    const pool = mysql.createPool({
        ...clientOpts,
        user: 'camdbusr',
        password: 'V7Dbz5NF',
        database: 'camera',
    });
    //let conn = await pool.getConnection();
    exports.pool = pool;
    //exports.conn = conn;
}

let conn1 = connection()
exports.conn1 = conn1;*/